package com.grm.workflow.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.grm.common.entity.Result;
import com.grm.workflow.model.WfCategory;
import com.grm.workflow.request.WfCategoryQueryParam;
import com.grm.workflow.service.WfCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/workflow/category")
public class WfCategoryController {
    @Autowired
    private WfCategoryService wfCategoryService;

    @GetMapping("query/all")
    public Result queryAll() {
        List<WfCategory> wfCategoryList = wfCategoryService.queryAll();
        return Result.success(wfCategoryList);
    }

    @PostMapping("/list")
    public Result querySelective(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestBody WfCategoryQueryParam queryParam) {
        // 开启分页
        PageHelper.startPage(pageNum, pageSize);
        List<WfCategory> wfCategoryList = wfCategoryService.querySelective(queryParam);
        PageInfo<WfCategory> pageInfo = new PageInfo<>(wfCategoryList);
        return Result.success(pageInfo.getList(), pageInfo.getTotal());
    }

    @PostMapping("/add")
    public Result add(@RequestBody WfCategory wfCategory) {
        wfCategoryService.add(wfCategory);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody WfCategory wfCategory) {
        wfCategoryService.update(wfCategory);
        return Result.success();
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody List<Long> ids) {
        wfCategoryService.delete(ids);
        return Result.success();
    }
}
